home *** CD-ROM | disk | FTP | other *** search
/ Linux Cubed Series 7: Sunsite / Linux Cubed Series 7 - Sunsite Vol 1.iso / system / manual-p / olxvman.tgz / olxvman.tar / olxvman / src / buttons.c next >
C/C++ Source or Header  |  1990-10-08  |  21KB  |  729 lines

  1. /*
  2.  * xman - X window system manual page display program.
  3.  *
  4.  * $XConsortium: buttons.c,v 1.19 89/12/15 12:06:38 kit Exp $
  5.  * $Header: buttons.c,v 1.19 89/12/15 12:06:38 kit Exp $
  6.  *
  7.  * Copyright 1987, 1988 Massachusetts Institute of Technology
  8.  *
  9.  * Permission to use, copy, modify, and distribute this software and its
  10.  * documentation for any purpose and without fee is hereby granted, provided
  11.  * that the above copyright notice appear in all copies and that both that
  12.  * copyright notice and this permission notice appear in supporting
  13.  * documentation, and that the name of M.I.T. not be used in advertising or
  14.  * publicity pertaining to distribution of the software without specific,
  15.  * written prior permission.  M.I.T. makes no representations about the
  16.  * suitability of this software for any purpose.  It is provided "as is"
  17.  * without express or implied warranty.
  18.  *
  19.  * Author:    Chris D. Peterson, MIT Project Athena
  20.  * Created:   October 27, 1987
  21.  */
  22.  
  23. #if ( !defined(lint) && !defined(SABER))
  24.   static char rcs_version[] = "$Athena: buttons.c,v 4.5 88/12/19 13:46:34 kit Exp $";
  25. #endif
  26.  
  27. #include "globals.h"
  28.  
  29. /* The files with the icon bits in them. */
  30.  
  31. #include "icon_open.h"
  32. #include "icon_help.h"
  33. #include "iconclosed.h"
  34.  
  35. static void CreateOptionMenu(), CreateSectionMenu();
  36. ManpageGlobals * InitPsuedoGlobals();
  37.  
  38. /*    Function Name: MakeTopBox
  39.  *    Description: This funtion creates the top menu, in a shell widget.
  40.  *    Arguments: none.
  41.  *    Returns: the top level widget
  42.  */
  43.  
  44. #define TOPARGS 5
  45.  
  46. void
  47. MakeTopBox()
  48. {
  49.   Widget top, form, command, label; /* widgets. */
  50.   Arg arglist[TOPARGS];        /* An argument list */
  51.   Cardinal num_args = 0;    /* The number of arguments. */
  52.   ManpageGlobals * man_globals;
  53.   static char * full_size[] = {
  54.     "topLabel", MANPAGE_BUTTON, NULL
  55.   };
  56.   static char * half_size[] = {
  57.     HELP_BUTTON, QUIT_BUTTON, NULL
  58.   };
  59.   
  60. /* create the top icon. */
  61.  
  62.   num_args = 0;
  63.   XtSetArg(arglist[num_args], XtNiconPixmap,
  64.        XCreateBitmapFromData( XtDisplay(initial_widget), 
  65.                  XtScreen(initial_widget)->root,
  66.                  iconclosed_bits, iconclosed_width,
  67.                  iconclosed_height));
  68.   num_args++;
  69.  
  70.   top = XtCreatePopupShell(TOPBOXNAME, topLevelShellWidgetClass, 
  71.                initial_widget, arglist, num_args);
  72.  
  73.   form = XtCreateManagedWidget("form", formWidgetClass, top, 
  74.                    NULL, (Cardinal) 0);
  75.  
  76.   label = XtCreateManagedWidget("topLabel", labelWidgetClass, form, 
  77.                    NULL, (Cardinal) 0);
  78.  
  79.   num_args = 0;
  80.   XtSetArg(arglist[num_args], XtNfromVert, label); num_args++;
  81.   command = XtCreateManagedWidget(HELP_BUTTON, commandWidgetClass, form, 
  82.                   arglist, num_args);
  83.  
  84.   /* use same vertical as help widget. */
  85.   XtSetArg(arglist[num_args], XtNfromHoriz, command); num_args++;
  86.   command = XtCreateManagedWidget(QUIT_BUTTON, commandWidgetClass, form, 
  87.                   arglist, num_args);
  88.  
  89.   num_args = 0;
  90.   XtSetArg(arglist[num_args], XtNfromVert, command); num_args++;
  91.   command = XtCreateManagedWidget(MANPAGE_BUTTON, commandWidgetClass, form, 
  92.                   arglist, num_args);
  93.  
  94.   help_widget = NULL;        /* We have not seen the help yet. */
  95.  
  96.   FormUpWidgets(form, full_size, half_size);
  97.  
  98.   man_globals = (ManpageGlobals*) XtMalloc( (Cardinal) sizeof(ManpageGlobals));
  99.   man_globals->label = NULL;
  100.   man_globals->manpagewidgets.directory = NULL;
  101.   man_globals->manpagewidgets.manpage = NULL;
  102.   man_globals->manpagewidgets.box = NULL;
  103.   man_globals->current_directory = 0;
  104.   MakeSearchWidget(man_globals, top);
  105.   MakeSaveWidgets(man_globals, top);
  106.  
  107.   XtRealizeWidget(top);
  108.   SaveGlobals( (man_globals->This_Manpage = top), man_globals);
  109.   XtMapWidget(top);
  110.   AddCursor(top, resources.cursors.top);
  111. }
  112.  
  113. /*    Function Name: CreateManpage
  114.  *    Description: Creates a new manpage.
  115.  *    Arguments: none.
  116.  *    Returns: none.
  117.  */
  118.  
  119. Widget
  120. CreateManpage( file )
  121. FILE * file;
  122. {
  123.   ManpageGlobals * man_globals;    /* The psuedo global structure. */
  124.   static void StartManpage();
  125.  
  126.   man_globals = InitPsuedoGlobals();
  127.   CreateManpageWidget(man_globals, MANNAME, TRUE);
  128.   
  129.   if (file == NULL)
  130.     StartManpage( man_globals, OpenHelpfile(man_globals), FALSE );
  131.   else {
  132.     OpenFile(man_globals, file);
  133.     StartManpage( man_globals, FALSE, TRUE);
  134.   }
  135.   return(man_globals->This_Manpage);
  136. }
  137.  
  138. /*    Function Name: InitPsuedoGlobals
  139.  *    Description: Initializes the psuedo global variables.
  140.  *    Arguments: none.
  141.  *    Returns: a pointer to a new pseudo globals structure.
  142.  */
  143.  
  144. ManpageGlobals * 
  145. InitPsuedoGlobals()
  146. {
  147.   ManpageGlobals * man_globals;
  148.  
  149.   /*
  150.    * Allocate necessary memory. 
  151.    */
  152.  
  153.   man_globals = (ManpageGlobals *) 
  154.                 XtMalloc( (Cardinal) sizeof(ManpageGlobals));
  155.  
  156.   man_globals->section_name = (char **) XtMalloc( (Cardinal) (sections *
  157.                                   sizeof(char *)));
  158.   man_globals->manpagewidgets.box = (Widget *) XtCalloc( (Cardinal) sections,
  159.                             (Cardinal) sizeof(Widget));
  160.   
  161.   /* Initialize the number of screens that will be shown */
  162.  
  163.   man_globals->both_shown = resources.both_shown_initial;
  164.   
  165.   return(man_globals);
  166. }
  167.   
  168. /*    Function Name: CreateManpageWidget
  169.  *    Description: Creates a new manual page widget.
  170.  *    Arguments: man_globals - a new man_globals structure.
  171.  *                 name         - name of this shell widget instance.
  172.  *                 full_instance - if true then create a full manpage,
  173.  *                                 otherwise create stripped down version
  174.  *                                 used for help.
  175.  *    Returns: none
  176.  */
  177.  
  178. #define MANPAGEARGS 10
  179.  
  180. void
  181. CreateManpageWidget(man_globals, name, full_instance)
  182. ManpageGlobals * man_globals;
  183. char * name;
  184. Boolean full_instance;
  185. {
  186.   Arg arglist[MANPAGEARGS];    /* An argument list for widget creation */
  187.   Cardinal num_args;        /* The number of arguments in the list. */
  188.   Widget top, pane, hpane, sections;    /* Widgets */
  189.   ManPageWidgets * mpw = &(man_globals->manpagewidgets);
  190.  
  191.   num_args = (Cardinal) 0;
  192.   XtSetArg(arglist[num_args], XtNwidth, default_width);
  193.   num_args++; 
  194.   XtSetArg(arglist[num_args], XtNheight, default_height);
  195.   num_args++; 
  196.  
  197.   top = XtCreatePopupShell(name, topLevelShellWidgetClass, initial_widget,
  198.                arglist, num_args);
  199.  
  200.   man_globals->This_Manpage = top; /* pointer to root widget of Manualpage. */
  201.   num_args = 0;
  202.   if (full_instance)
  203.     XtSetArg(arglist[num_args], XtNiconPixmap,
  204.          XCreateBitmapFromData( XtDisplay(top), XtScreen(top)->root,
  205.                    icon_open_bits, icon_open_width,
  206.                    icon_open_height));
  207.   else 
  208.     XtSetArg(arglist[num_args], XtNiconPixmap,
  209.          XCreateBitmapFromData( XtDisplay(top), XtScreen(top)->root,
  210.                    icon_help_bits, icon_help_width,
  211.                    icon_help_height));
  212.   num_args++;
  213.   XtSetValues(top, arglist, num_args);
  214.  
  215.   pane = XtCreateManagedWidget("Manpage_Vpane", panedWidgetClass, top, NULL, 
  216.                    (Cardinal) 0);
  217.  
  218. /* Create menu bar. */
  219.  
  220.   hpane = XtCreateManagedWidget("horizPane", panedWidgetClass,
  221.                   pane, NULL, (Cardinal) 0);
  222.   num_args = 0;
  223.   XtSetArg(arglist[num_args], XtNmenuName, OPTION_MENU); num_args++;
  224.   (void) XtCreateManagedWidget("options", menuButtonWidgetClass,
  225.                   hpane, arglist, num_args);
  226.  
  227.   CreateOptionMenu(man_globals, top);
  228.  
  229.   num_args = 0;
  230.   XtSetArg(arglist[num_args], XtNmenuName, SECTION_MENU); num_args++;
  231.   sections = XtCreateManagedWidget("sections", menuButtonWidgetClass,
  232.                    hpane, arglist, num_args);
  233.  
  234.   XtSetArg(arglist[0], XtNlabel, SHOW_BOTH);
  235.   XtSetValues(man_globals->both_screens_entry, arglist, (Cardinal) 1);
  236.  
  237.   if (full_instance) {
  238.     MakeSearchWidget(man_globals, top);
  239.     CreateSectionMenu(man_globals, top);
  240.     MakeSaveWidgets(man_globals, top);
  241.   } else {
  242.     XtSetSensitive(sections, FALSE);       
  243.     XtSetArg(arglist[0], XtNsensitive, FALSE);
  244.     XtSetValues(man_globals->dir_entry, arglist, ONE);
  245.     XtSetValues(man_globals->manpage_entry, arglist, ONE);
  246.     XtSetValues(man_globals->help_entry, arglist, ONE);
  247.     XtSetValues(man_globals->search_entry, arglist, ONE);
  248.     XtSetValues(man_globals->both_screens_entry, arglist, ONE);
  249.   }
  250.  
  251.   man_globals->label = XtCreateManagedWidget(MANNAME, labelWidgetClass,
  252.                          hpane, NULL, (Cardinal) 0);
  253.  
  254. /* Create Directory */
  255.  
  256.   if (full_instance) {
  257.     num_args = 0;
  258.     XtSetArg(arglist[num_args], XtNallowVert, TRUE);
  259.     num_args++;
  260.     
  261.     mpw->directory = XtCreateWidget(DIRECTORY_NAME, viewportWidgetClass,
  262.                     pane, arglist, num_args);
  263.     
  264.     man_globals->current_directory = INITIAL_DIR;
  265.     MakeDirectoryBox(man_globals, mpw->directory,
  266.              mpw->box + man_globals->current_directory, 
  267.              man_globals->current_directory );
  268.     XtManageChild(mpw->box[man_globals->current_directory]);
  269.   }
  270.  
  271. /* Create Manpage */
  272.  
  273.   mpw->manpage = XtCreateWidget(MANUALPAGE, scrollByLineWidgetClass,
  274.                 pane, NULL, (Cardinal) 0);
  275. }
  276.  
  277. /*    Function Name: StartManpage
  278.  *    Description: Starts up a new manpage.
  279.  *    Arguments: man_globals - the psuedo globals variable.
  280.  *                 help - is this a help file?
  281.  *                 page - Is there a page to display?
  282.  *    Returns: none.
  283.  */
  284.  
  285. static void
  286. StartManpage(man_globals, help, page)
  287. ManpageGlobals * man_globals;
  288. Boolean help, page;
  289. {
  290.   Widget dir = man_globals->manpagewidgets.directory;
  291.   Widget manpage = man_globals->manpagewidgets.manpage;
  292.   Widget label = man_globals->label;
  293.   Arg arglist[1];
  294.  
  295. /* 
  296.  * If there is a helpfile then put up both screens if both_show is set.
  297.  */
  298.  
  299.   if (page || help) {
  300.     if (help) 
  301.       strcpy(man_globals->manpage_title, "Xman Help");
  302.  
  303.     if (man_globals->both_shown) {
  304.       XtManageChild(dir);
  305.       man_globals->dir_shown = TRUE;
  306.  
  307.       XtSetArg(arglist[0], XtNpreferredPaneSize, resources.directory_height);
  308.       XtSetValues(dir, arglist, (Cardinal) 1);
  309.  
  310.       XtSetArg(arglist[0], XtNsensitive, FALSE);
  311.       XtSetValues(man_globals->manpage_entry, arglist, ONE);
  312.       XtSetValues(man_globals->dir_entry, arglist, ONE);
  313.  
  314.       XtSetArg(arglist[0], XtNlabel, SHOW_ONE);
  315.       XtSetValues(man_globals->both_screens_entry, arglist, ONE);
  316.       ChangeLabel(label,
  317.           man_globals->section_name[man_globals->current_directory]);
  318.     }
  319.     else {
  320.       ChangeLabel(label,man_globals->manpage_title);
  321.     }
  322.     XtManageChild(manpage);
  323.     man_globals->dir_shown = FALSE;
  324.   }
  325. /*
  326.  * Since There is file to display, put up directory and do not allow change
  327.  * to manpage, show both, or help.
  328.  */
  329.   else {            
  330.     XtManageChild(dir);
  331.     man_globals->dir_shown = TRUE;
  332.     XtSetArg(arglist[0], XtNsensitive, FALSE);
  333.     XtSetValues(man_globals->manpage_entry,        arglist, ONE);
  334.     XtSetValues(man_globals->help_entry,           arglist, ONE);
  335.     XtSetValues(man_globals->both_screens_entry,   arglist, ONE);
  336.     man_globals->both_shown = FALSE;
  337.     ChangeLabel(label,
  338.         man_globals->section_name[man_globals->current_directory]);
  339.   }
  340.  
  341. /*
  342.  * Start 'er up, and change the cursor.
  343.  */
  344.  
  345.   XtRealizeWidget( man_globals->This_Manpage );
  346.   SaveGlobals( man_globals->This_Manpage, man_globals);
  347.   XtMapWidget( man_globals->This_Manpage );
  348.  
  349.   AddCursor( man_globals->This_Manpage, resources.cursors.manpage);
  350. }
  351.  
  352. /*      Function Name: MenuDestroy
  353.  *      Description: free's data associated with menu when it is destroyed.
  354.  *      Arguments: w - menu widget.
  355.  *                 free_me - data to free.
  356.  *                 junk - not used.
  357.  *      Returns: none.
  358.  */
  359.  
  360. /* ARGSUSED */
  361. static void
  362. MenuDestroy(w, free_me, junk)
  363. Widget w;
  364. caddr_t free_me, junk;
  365. {
  366.   XtFree( (char *) free_me);
  367. }
  368.  
  369. /*      Function Name:   CreateOptionMenu
  370.  *      Description: Create the option menu.
  371.  *      Arguments: man_globals - the manual page globals.
  372.  *                 parent - the button that activates the menu.
  373.  *      Returns: none.
  374.  */
  375.  
  376. static void
  377. CreateOptionMenu(man_globals, parent)
  378. ManpageGlobals * man_globals;
  379. Widget parent;
  380. {
  381.   Widget menu, entry;
  382.   int i;
  383.   static char * option_names[] = {    /* Names of the buttons. */
  384.     DIRECTORY,
  385.     MANPAGE,
  386.     HELP,
  387.     SEARCH,
  388.     BOTH_SCREENS, 
  389.     REMOVE_MANPAGE,
  390.     OPEN_MANPAGE,
  391.     SHOW_VERSION,
  392.     QUIT
  393.   };
  394.  
  395.   menu = XtCreatePopupShell(OPTION_MENU, simpleMenuWidgetClass, parent,
  396.                 NULL, (Cardinal) 0);
  397.   man_globals->option_menu = menu;
  398.   
  399.   for (i = 0 ; i < NUM_OPTIONS ; i++) {
  400.     entry = XtCreateManagedWidget(option_names[i], smeBSBObjectClass,
  401.                   menu, NULL, ZERO);
  402.     XtAddCallback(entry, XtNcallback, OptionCallback, (caddr_t) man_globals);
  403.     switch (i) {
  404.     case 0:
  405.     man_globals->dir_entry = entry;
  406.     break;
  407.     case 1:
  408.     man_globals->manpage_entry = entry;
  409.     break;
  410.     case 2:
  411.     man_globals->help_entry = entry;
  412.     break;
  413.     case 3:
  414.     man_globals->search_entry = entry;
  415.     break;
  416.     case 4:
  417.     man_globals->both_screens_entry = entry;
  418.     break;
  419.     case 5:
  420.     man_globals->remove_entry = entry;
  421.     break;
  422.     case 6:
  423.     man_globals->open_entry = entry;
  424.     break;
  425.     case 7:
  426.     man_globals->version_entry = entry;
  427.     break;
  428.     case 8:
  429.     man_globals->quit_entry = entry;
  430.     break;
  431.     default:
  432.     break;
  433.     }
  434.   }
  435. }
  436.  
  437. /*      Function Name: CreateSectionMenu
  438.  *      Description: Create the Section menu.
  439.  *      Arguments: man_globals - the manual page globals.
  440.  *                 parent - the button that activates the menu.
  441.  *      Returns: none.
  442.  */
  443.  
  444. static void
  445. CreateSectionMenu(man_globals, parent)
  446. ManpageGlobals * man_globals;
  447. Widget parent;
  448. {
  449.   Widget menu, entry;
  450.   int i;
  451.   MenuStruct * menu_struct;
  452.  
  453.   menu = XtCreatePopupShell(SECTION_MENU, simpleMenuWidgetClass, parent,
  454.                 NULL, (Cardinal) 0);
  455.  
  456.   for (i = 0 ; i < sections ; i ++) {
  457.     entry = XtCreateManagedWidget(manual[i].blabel, smeBSBObjectClass,
  458.                   menu, NULL, ZERO);
  459.     menu_struct = (MenuStruct *) XtMalloc(sizeof(MenuStruct));
  460.     menu_struct->data = (caddr_t) man_globals;
  461.     menu_struct->number = i;
  462.     XtAddCallback(entry, XtNcallback, DirPopupCallback, (caddr_t) menu_struct);
  463.     XtAddCallback(entry, XtNdestroyCallback,MenuDestroy, (caddr_t)menu_struct);
  464.  
  465.   }
  466. }
  467.  
  468. /*    Function Name: CreateManpageName
  469.  *    Description: Creates the manual page name for a given item.
  470.  *    Arguments: entry - the entry to convert.
  471.  *    Returns: the manual page properly allocated.
  472.  */
  473.  
  474. /*
  475.  * If the filename is foo.3     - Create an entry of the form:  foo
  476.  * If the filename is foo.3X11  - Create an entry of the form:  foo(X11)
  477.  * IF the filename is a.out.1   - Create an entry of the form:  a.out
  478.  */
  479.  
  480. char *
  481. CreateManpageName(entry)
  482. char * entry;
  483. {
  484.   char * cp;
  485.   char page[BUFSIZ];
  486.  
  487.   ParseEntry(entry, NULL, NULL, page);
  488.  
  489.   if ( (cp = rindex(page, '.')) != NULL)
  490.     if ( (strlen(cp) > 2) ) {
  491.       *cp++ = '(';
  492.       while( (cp[1] != '\0') ) {
  493.     *cp = *(cp + 1); 
  494.     cp++;
  495.       }
  496.       *cp++ = ')';
  497.       *cp = '\0';
  498.     }
  499.     else
  500.       *cp = '\0';  
  501.   
  502.   return(StrAlloc(page));
  503. }
  504.  
  505. /*    Function Name: CreateList
  506.  *    Description: this function prints a label in the directory list
  507.  *    Arguments: section - the manual section.
  508.  *    Returns: none
  509.  */
  510.  
  511. static char **
  512. CreateList(section)
  513. {
  514.   char ** ret_list, **current;
  515.   int count;
  516.  
  517.   ret_list = (char **) XtMalloc( (manual[section].nentries + 1) * 
  518.                    sizeof (char *));
  519.  
  520.   for (current = ret_list, count = 0 ; count < manual[section].nentries ;
  521.        count++, current++)
  522.     *current = CreateManpageName(manual[section].entries[count]);
  523.  
  524.   *current = NULL;        /* NULL terminate the list. */
  525.   return(ret_list);
  526. }
  527.  
  528. /*    Function Name: MakeDirectoryBox
  529.  *    Description: make a directory box.
  530.  *    Arguments: man_globals - the psuedo global structure for each manpage.
  531.  *                 parent - this guys parent widget.
  532.  *                 dir_disp - the directory display widget.
  533.  *                 section - the section number.
  534.  *    Returns: none.
  535.  */
  536.  
  537. void
  538. MakeDirectoryBox(man_globals,parent,dir_disp,section)
  539. ManpageGlobals *man_globals;
  540. Widget parent, *dir_disp;
  541. int section;
  542. {
  543.   Arg arglist[10];
  544.   Cardinal num_args;
  545.   char * name, label_name[BUFSIZ];
  546.  
  547.   if (*dir_disp != NULL)    /* If we have one, don't make another. */
  548.     return;
  549.  
  550.   name = manual[section].blabel;   /* Set the section name */
  551.   sprintf(label_name,"Directory of: %s",name);
  552.   man_globals->section_name[section] = StrAlloc(label_name);
  553.  
  554.   num_args = 0;
  555.   XtSetArg(arglist[num_args], XtNlist, CreateList(section));
  556.   num_args++;
  557.   XtSetArg(arglist[num_args], XtNfont, resources.fonts.directory);
  558.   num_args++;
  559.   
  560.   *dir_disp = XtCreateWidget(DIRECTORY_NAME, listWidgetClass, parent,
  561.                  arglist, num_args);
  562.   
  563.   XtAddCallback(*dir_disp, XtNcallback,
  564.         DirectoryHandler, (caddr_t) man_globals);
  565. }
  566.  
  567. /*    Function Name: MakeSaveWidgets.
  568.  *    Description: This functions creates two popup widgets, the please 
  569.  *                   standby widget and the would you like to save widget.
  570.  *    Arguments: man_globals - the psuedo globals structure for each man page
  571.  *                 parent - the parent for both popups.
  572.  *    Returns: none.
  573.  */
  574.  
  575. void
  576. MakeSaveWidgets(man_globals, parent)
  577. ManpageGlobals *man_globals;
  578. Widget parent;
  579. {
  580.   Widget shell, dialog; /* misc. widgets. */
  581.   
  582. /* make the please stand by popup widget. */
  583.  
  584.   shell = XtCreatePopupShell( "pleaseStandBy", transientShellWidgetClass,
  585.                   parent, NULL, (Cardinal) 0);
  586.  
  587.   man_globals->standby = XtCreateManagedWidget("label", labelWidgetClass, 
  588.                            shell, NULL, (Cardinal) 0);
  589.   XtRealizeWidget(shell);
  590.   AddCursor(shell,resources.cursors.top);
  591.  
  592.   man_globals->save = XtCreatePopupShell("likeToSave",
  593.                      transientShellWidgetClass,
  594.                      parent, NULL, (Cardinal) 0);
  595.  
  596.   dialog = XtCreateManagedWidget("dialog", dialogWidgetClass, 
  597.                  man_globals->save, NULL, (Cardinal) 0);
  598.  
  599.   XawDialogAddButton(dialog, FILE_SAVE, NULL, NULL);
  600.   XawDialogAddButton(dialog, CANCEL_FILE_SAVE, NULL, NULL);
  601.  
  602.   XtRealizeWidget(man_globals->save);
  603.   AddCursor(man_globals->save, resources.cursors.top);
  604. }
  605.  
  606. /*      Function Name: FormUpWidgets
  607.  *      Description: Sizes widgets to look nice.
  608.  *      Arguments: parent - the common parent of all the widgets.
  609.  *                 full_size - array of widget names that will he full size.
  610.  *                 half_size - array of widget names that will he half size.
  611.  *      Returns: none
  612.  */
  613.  
  614. void
  615. FormUpWidgets(parent, full_size, half_size)
  616. Widget parent;
  617. char ** full_size, ** half_size;
  618. {
  619.   static Widget * ConvertNamesToWidgets();
  620.   Widget * full_widgets, * half_widgets, *temp, long_widget;
  621.   Dimension longest, length, b_width;
  622.   int interior_dist;
  623.   Arg arglist[2];
  624.     
  625.   full_widgets = ConvertNamesToWidgets(parent, full_size);
  626.   half_widgets = ConvertNamesToWidgets(parent, half_size);
  627.   
  628.   long_widget = NULL;
  629.   longest = 0;
  630.   XtSetArg(arglist[0], XtNwidth, &length);
  631.   XtSetArg(arglist[1], XtNborderWidth, &b_width);
  632.  
  633. /*
  634.  * Find Longest widget.
  635.  */
  636.  
  637.   for ( temp = full_widgets ; *temp != (Widget) NULL ; temp++) {
  638.     XtGetValues(*temp, arglist, (Cardinal) 2);
  639.     length += 2 * b_width;
  640.     if (length > longest) {
  641.       longest = length;
  642.       long_widget = *temp;
  643.     }
  644.   }
  645.  
  646.   if (long_widget == (Widget) NULL) {          /* Make sure we found one. */
  647.     PrintWarning(GetGlobals(parent), 
  648.          "Could not find longest widget, aborting...");
  649.     XtFree(full_widgets);
  650.     XtFree(half_widgets);
  651.     return;
  652.   }
  653.  
  654. /*
  655.  * Set all other full_widgets to this length.
  656.  */
  657.  
  658.   for ( temp = full_widgets ; *temp != (Widget) NULL ; temp++ )
  659.     if ( long_widget != *temp) {
  660.       Dimension width, border_width;
  661.  
  662.       XtSetArg(arglist[0], XtNborderWidth, &border_width);
  663.       XtGetValues(*temp, arglist, (Cardinal) 1);
  664.     
  665.       width = longest - 2 * border_width;
  666.       XtSetArg(arglist[0], XtNwidth, width);
  667.       XtSetValues(*temp, arglist, (Cardinal) 1);
  668.     }
  669.  
  670. /*
  671.  * Set all the half widgets to the right length.
  672.  */
  673.  
  674.   XtSetArg(arglist[0], XtNdefaultDistance, &interior_dist);
  675.   XtGetValues(parent, arglist, (Cardinal) 1);
  676.   
  677.   for ( temp = half_widgets ; *temp != (Widget) NULL ; temp++) {
  678.     Dimension width, border_width;
  679.  
  680.     XtSetArg(arglist[0], XtNborderWidth, &border_width);
  681.     XtGetValues(*temp, arglist, (Cardinal) 1);
  682.     
  683.     width = (longest - interior_dist)/2 - 2 * border_width;
  684.     XtSetArg(arglist[0], XtNwidth, width);
  685.     XtSetValues(*temp, arglist, (Cardinal) 1);
  686.   }
  687.  
  688.   XtFree(full_widgets);
  689.   XtFree(half_widgets);
  690. }
  691.   
  692. /*      Function Name: ConvertNamesToWidgets
  693.  *      Description: Convers a list of names into a list of widgets.
  694.  *      Arguments: parent - the common parent of these widgets.
  695.  *                 names - an array of widget names.
  696.  *      Returns: an array of widget id's.
  697.  */
  698.  
  699. static Widget *
  700. ConvertNamesToWidgets(parent, names)
  701. Widget parent;
  702. char ** names;
  703. {
  704.   char ** temp;
  705.   Widget * ids, * temp_ids;
  706.   int count;
  707.  
  708.   for (count = 0, temp = names; *temp != NULL ; count++, temp++);
  709.  
  710.   ids = (Widget *) XtMalloc( (count + 1) * sizeof(Widget));
  711.  
  712.   
  713.   for ( temp_ids = ids; *names != NULL ; names++, temp_ids++) {
  714.     *temp_ids = XtNameToWidget(parent, *names);
  715.     if (*temp_ids == NULL) {
  716.       char error_buf[BUFSIZ];
  717.     
  718.       sprintf(error_buf, "Could not find widget named '%s'", *names);
  719.       PrintError(error_buf);
  720.       XtFree(ids);
  721.       return(NULL);
  722.     }
  723.   }
  724.   
  725.   *temp_ids = (Widget) NULL;
  726.   return(ids);
  727. }
  728.     
  729.